package org.example.strategy;

import java.util.LinkedList;

public class InsertStrategy implements EditorStrategy{
    private Integer lineNumber;
    private String content;
    private LinkedList<String> fileContents;

    public InsertStrategy(Integer lineNumber,String content,LinkedList<String> fileContents) {
        this.content = content;
        this.fileContents = fileContents;
        this.lineNumber = lineNumber;
    }
    public LinkedList<String> getFileContents(){
        return fileContents;
    }

    @Override
    public void performAction() {
        if (lineNumber < 0 || lineNumber > fileContents.size()){
            this.fileContents.add(content);
        }
        else this.fileContents.add(lineNumber - 1,content);
    }
}
